﻿using System;
using System.Text;
using System.Web;
using Cms.Application;
using Cms.Application.Admin.Presenters;
using Cms.Application.Admin.Views;
using Cms.Web.Framework.Controls;
using iLib.Web.UI;

namespace Cms.Web.UI.Admin.TinyMCEIntegration
{
    public partial class UploadFilesPopup : AdminPopupBasePage, IUploadView
    {
        private UploadPresenter _presenter;

        #region IUploadView Members

        public string ContextTranslationFile
        {
            get { return "Admin/Translations/Upload.xml"; }
        }


        public string Localization
        {
            get
            {
                HttpCookie cookie = Request.Cookies["FrediumAdminLocalization"];
                if (cookie != null)
                    return cookie.Value;
                else
                    return "en-US";
            }
        }

        public void SetFolderName(string name)
        {
            litFolder.Text = name;
        }

        #endregion

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Response.HeaderEncoding = Encoding.UTF8;
            baseTag.Attributes.Add("href", Url.FullPath);
            Page.Header.Controls.Add(new iLibRegistrator());
            _presenter = new UploadPresenter(this);
            Title = Translator.GetText(ContextTranslationFile, "Heading", Localization);
            if (!Page.IsPostBack)
            {
                form1.Action = Url.FoldersAndPage + Url.Querystring;
                hlCancel.NavigateUrl = "Admin/TinyMCEIntegration/MediaPopup.aspx";
            }
            string script = "function displayOverwriteConfirmation(existingFiles) { " +
                            "document.getElementById('lblExistingFiles').innerHTML = existingFiles;" +
                            "cms.Dialogs.Confirm(validationCallback, '" +
                            Translator.GetText(ContextTranslationFile, "OverwriteHeader", Localization) + "', null, '" +
                            Translator.GetText(ContextTranslationFile, "OverwriteOK", Localization) + "', '" +
                            Translator.GetText(ContextTranslationFile, "OverwriteCancel", Localization) +
                            "', true, null, 'overwriteWarning');" +
                            "}";
            ClientScriptProxy.Current.RegisterClientScriptBlock(this, GetType(), "validate", script, true);
            ifrCheckFiles.Attributes.Add("src", Url.VirtualPath + "Admin/UploadCheck.aspx");
        }
    }
}